/*
 * Copyright 2009 Paul Loy
 * 
 * This file is part of java-mod-auth-token-urigen, a library to allow users to
 * create mod_auth_token compatible uris in Java.
 * 
 * java-mod-auth-token-urigen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * java-mod-auth-token-urigen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with java-mod-auth-token-urigen.  If not, see <http://www.gnu.org/licenses/>.
 */
 
package com.keteracel.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author Paul_Loy (keteracel)
 */
public class MD5Digester {

    public static String toMD5(String source) {
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        digest.update(source.getBytes());
        byte[] hash = digest.digest();
        return StringUtils.byteArrayToHexString(hash);
    }

}
